package ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fy.fyzf.R;
import com.fy.fyzf.api.ApiConstant;
import com.fy.fyzf.base.BaseFragment;
import com.fy.fyzf.bean.AreaListBean;
import com.fy.fyzf.bean.CategoryBean;
import com.fy.fyzf.bean.FiltrateBean;
import com.fy.fyzf.bean.HomeBannerBean;
import com.fy.fyzf.bean.HousesBean;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.bean.HousingCountBean;
import com.fy.fyzf.bean.PriceFilterBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.SearchPassengerBean;
import com.fy.fyzf.dialog.AreaFilterPopwindow;
import com.fy.fyzf.dialog.CityDetailFilterPopwindow;
import com.fy.fyzf.dialog.FlowPopWindow;
import com.fy.fyzf.dialog.PriceFilterPopwindow;
import com.fy.fyzf.presenter.HouseSoucePresenter;
import com.fy.fyzf.utils.AppUtils;
import com.fy.fyzf.utils.GetJsonDataUtil;
import com.fy.fyzf.utils.ShareHelper;
import com.fy.fyzf.view.HouseSouceView;
import com.fy.fyzf.view.SpacesItemDecoration;
import com.fy.fyzf.weight.CommonDialog;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import ui.activity.AllHousingActivity;
import ui.activity.HouseDetailActivity;
import ui.adapter.AreaListAdapter;
import ui.adapter.MatchHousingAdapter;
import ui.adapter.PriceFilterAdapter;

/**
 * 房源
 * A simple {@link Fragment} subclass.
 * Use the {@link AllHousingFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class AllHousingFragment extends BaseFragment<HouseSoucePresenter> implements HouseSouceView {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.et_search)
    EditText etSearch;
    //    @BindView(R.id.tv_add)
//    TextView tvAdd;
    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    @BindView(R.id.smartRefresh)
    SmartRefreshLayout smartRefresh;
    @BindView(R.id.rl_area)
    RelativeLayout rlArea;
    @BindView(R.id.rl_price)
    RelativeLayout rlPrice;
    @BindView(R.id.rl_mianji)
    RelativeLayout rlMianji;
    @BindView(R.id.rl_more)
    RelativeLayout rlMore;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;

    @BindView(R.id.tv_save)
    TextView tvSave;
    private int page = 1;
    private int tag = 1;
    private int pageSize = 10;

    // TODO: Rename and change types of parameters
    private int customerId;
    private int mParam2;

    public static int cityType = 1;

    public AllHousingFragment() {
        // Required empty public constructor
    }

    // TODO: Rename and change types and number of parameters
    public static AllHousingFragment newInstance(int param1, int param2) {
        AllHousingFragment fragment = new AllHousingFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, param1);
        args.putInt(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    String JsonData;
    List<CategoryBean> categoryList2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            customerId = getArguments().getInt(ARG_PARAM1);
            mParam2 = getArguments().getInt(ARG_PARAM2);
        }
        JsonData = new GetJsonDataUtil().getJson(getActivity(), "menu.json");//获取assets目录下的json文件数据
        categoryList2 = new Gson().fromJson(JsonData, new TypeToken<List<CategoryBean>>() {
        }.getType());
    }


    @Override
    protected HouseSoucePresenter createPresenter() {
        return new HouseSoucePresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_all_housing;
    }

    @Override
    protected void loadData() {

    }

    MatchHousingAdapter housesListAdapter;
    TextWatcher textWatcher;
    private Intent intentCallBack;
    private SearchPassengerBean searchPassengerBean = new SearchPassengerBean();
    boolean isMulit;

    @Override
    public void initView(View rootView) {
        super.initView(rootView);
        initParam();
        if (mParam2 == 2) {
            isMulit = false;
        } else {
            isMulit = true;
        }
        housesListAdapter = new MatchHousingAdapter(getActivity(), mParam2, isMulit);
        recycleView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recycleView.addItemDecoration(new SpacesItemDecoration(16));
        recycleView.setAdapter(housesListAdapter);
        if (mParam2 == 1) {
            tvSave.setBackground(getResources().getDrawable(R.drawable.shape_save_housing));
            tvSave.setText("确认收藏");
        } else {
            tvSave.setText("确定");
            tvSave.setBackground(getResources().getDrawable(R.drawable.shape_add_house));
        }

        housesListAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                List<HousesListBean.ListBean> data = adapter.getData();
                String url = ApiConstant.BASE_SERVER_URL + "shareHousing/getHousing?housingId="+data.get(position).getHousingId();

                if (view.getId() == R.id.share_wx) {
                    ShareHelper shareHelper = new ShareHelper(getActivity());
                    shareHelper.shareWx(data.get(position).getHousingImage(), url);
                } else if (view.getId() == R.id.share_pyq) {
                    ShareHelper shareHelper = new ShareHelper(getActivity());
                    shareHelper.shareWechatMoments(data.get(position).getHousingImage(), url);
                } else if (view.getId() == R.id.iv_star) {
                    CommonDialog commonDialog = new CommonDialog(getActivity());
                    if (data.get(position).getCollection() == null) {
                        commonDialog.setContent("是否收藏该房源？");
                    } else {
                        commonDialog.setContent("是否取消收藏该房源？");
                    }
                    commonDialog.toggleDialog();
                    commonDialog.setOnconirmListener(new CommonDialog.OnConfirmClickListener() {
                        @Override
                        public void onClick() {
                            searchPassengerBean.setCustomerId(customerId);
                            searchPassengerBean.setHousingId(data.get(position).getHousingId());
                            if (data.get(position).getCollection() == null) {
                                mPresenter.addCollectHousing(searchPassengerBean, position);
                            } else {
                                mPresenter.removeCollectionHousing(searchPassengerBean, position);
                            }
                            commonDialog.toggleDialog();
                        }
                    });
                }
            }
        });

        if (textWatcher != null) {
            etSearch.removeTextChangedListener(textWatcher);
        }
        textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                Log.e("搜索", s.toString());
                if (TextUtils.isEmpty(s.toString())) {
                    tvCancel.setBackgroundResource(R.mipmap.icon_search);
                    tvCancel.setText("");
                    tag = 1;
                    page = 1;
                    housesBean = new HousesBean();
                    housesBean.setPageNum(page);
                    housesBean.setPageSize(pageSize);
                    loadData();
                } else {
                    tvCancel.setBackgroundResource(0);
                    tvCancel.setText("取消");
                }
            }
        };
        etSearch.addTextChangedListener(textWatcher);

        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    if (!TextUtils.isEmpty(etSearch.getText().toString().trim())) {
                        tag = 1;
                        housesBean = new HousesBean();
                        housesBean.setPageNum(page);
                        housesBean.setPageSize(pageSize);
                        housesBean.setFloorName(etSearch.getText().toString());
                        initData();
                    }
                    return true;
                }
                return false;
            }
        });
        smartRefresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                page = 1;
                tag = 1;
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                initData();
            }
        });
        smartRefresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                tag = 2;
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                initData();
            }
        });

        housesBean = new HousesBean();
        housesBean.setPageNum(page);
        housesBean.setPageSize(pageSize);

        housesListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                List<HousesListBean.ListBean> listBeans = adapter.getData();
                if (mParam2 == 1) {
                    Intent intent = new Intent(getActivity(), HouseDetailActivity.class);
                    intent.putExtra("housingid", listBeans.get(position).getHousingId());
                    intent.putExtra("collection", listBeans.get(position).getCollection());
                    intent.putExtra("customerId", customerId);
                    startActivity(intent);
                } else {
                    if (isMulit) {
                        if (listBeans.get(position).isCheck()) {
                            listBeans.get(position).setCheck(false);
                            housesListAdapter.selectMap.remove(position);
                        } else {
                            housesListAdapter.selectMap.put(position, true);
                            listBeans.get(position).setCheck(true);
                        }
                        housesListAdapter.notifyDataSetChanged();
                    } else {
                        housesListAdapter.setSelect(position);
                        HousesListBean.ListBean listBean = listBeans.get(position);
                        intentCallBack = new Intent();
                        intentCallBack.putExtra("data", listBean);
                    }
                }
            }
        });


    }

    private HousesBean housesBean;

    @Override
    public void initData() {
        super.initData();
        registerEventBus(this);
        SearchPassengerBean searchPassengerBean = new SearchPassengerBean();
        searchPassengerBean.setPageSize(pageSize);
        searchPassengerBean.setPageNum(page);
        searchPassengerBean.setCustomerId(customerId);
        mPresenter.getMatchHousingList(searchPassengerBean, false);
    }

    @OnClick({R.id.tv_save, R.id.tv_cancel, R.id.et_search, R.id.rl_area, R.id.rl_price, R.id.rl_mianji, R.id.rl_more})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_save:
                AllHousingActivity activity;
                if (mParam2 == 2) {
                    activity = (AllHousingActivity) getActivity();
                    activity.setResult(10001, intentCallBack);
                    activity.finish();
                } else {
                    activity = (AllHousingActivity) getActivity();
                    activity.setResult(10002,  new Intent().putExtra("data", housesListAdapter.getSelectedItem()));
                    activity.finish();
                }
                break;
            case R.id.tv_cancel:
                if (tvCancel.getText().equals("取消")) {
                    etSearch.setText("");
                    AppUtils.hideInput(etSearch);
                }
                break;
            case R.id.et_search:
                break;

            case R.id.rl_area:
                showAreaData();
                break;
            case R.id.rl_price:
                showPriceFilterDialog();
                break;
            case R.id.rl_mianji:
                showMianJiFilterDialog();
                break;
            case R.id.rl_more:
                showOtherFilterDialog();
                break;
            default:
        }
    }

    private void showMianJiFilterDialog() {
        AreaFilterPopwindow areaFilterPopwindow = new AreaFilterPopwindow(getActivity());
        areaFilterPopwindow.showPop(rlArea);
        PriceFilterAdapter priceFilterAdapter = areaFilterPopwindow.getPriceFilterAdapter();
        priceFilterAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                areaFilterPopwindow.onDismiss();

                tag = 1;
                page = 1;
                List<PriceFilterBean> data = adapter.getData();
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                housesBean.setDimension(data.get(position).getId());
                loadData();
            }
        });

    }

    private void showPriceFilterDialog() {
        PriceFilterPopwindow priceFilterPopwindow = new PriceFilterPopwindow(getActivity());
        priceFilterPopwindow.showPop(rlArea);
        PriceFilterAdapter priceFilterAdapter = priceFilterPopwindow.getPriceFilterAdapter();
        priceFilterAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                priceFilterPopwindow.onDismiss();
                tag = 1;
                page = 1;
                List<PriceFilterBean> data = adapter.getData();
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                housesBean.setPrice(data.get(position).getId());
                loadData();
            }
        });
    }

    Integer isBigYeZhu = null;
    Integer isGoodHouse = null;
    Integer houseStatus = 1;
    private List<FiltrateBean> dictList = new ArrayList<>();

    private void showOtherFilterDialog() {
        isBigYeZhu = null;
        isGoodHouse = null;
        houseStatus = 1;

        FlowPopWindow flowPopWindow = new FlowPopWindow(getActivity(), dictList);
        flowPopWindow.showAsDropDown(rlArea, 0, -10);
        flowPopWindow.setOnConfirmClickListener(new FlowPopWindow.OnConfirmClickListener() {
            @Override
            public void onConfirmClick() {
                StringBuilder sb = new StringBuilder();
                for (FiltrateBean fb : dictList) {
                    List<FiltrateBean.Children> cdList = fb.getChildren();
                    for (int x = 0; x < cdList.size(); x++) {
                        FiltrateBean.Children children = cdList.get(x);
                        if (children.isSelected()) {
                            sb.append(fb.getTypeId() + "" + children.getId());
                        }
                    }
                }
                int index;
                for (index = 2; index < sb.length(); index += 3) {
                    sb.insert(index, ',');
                }
                String[] array = sb.toString().split(",");
                if (array.length <= 0) {
                    return;
                }
                for (int i = 0; i < array.length; i++) {
                    if (!TextUtils.isEmpty(array[i])) {
                        if (array[i].startsWith("A")) { //第一个筛选
                            isBigYeZhu = Integer.parseInt(array[i].substring(array[i].length() - 1, array[i].length()));
                        } else if (array[i].startsWith("B")) {
                            isGoodHouse = Integer.parseInt(array[i].substring(array[i].length() - 1, array[i].length()));
                        } else if (array[i].startsWith("C")) {
                            houseStatus = Integer.parseInt(array[i].substring(array[i].length() - 1, array[i].length()));
                        }
                    }
                }

                tag = 1;
                page = 1;
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                housesBean.setQualityHouse(isGoodHouse);
                housesBean.setHousingStatus(houseStatus);
                loadData();
            }
        });
    }

    private void initParam() {
        String[] sexs = {"是", "否"};
        Integer[] idS = {1, 0};
        Integer[] statusId = {1, 2, 3, 4, 5, 6, 7};
        String[] colors = {"是", "否"};

        String[] company = {"有效", "已租", "暂缓", "我租", "租售", "我售", "非有效"};

        FiltrateBean fb1 = new FiltrateBean();
        fb1.setTypeName("是否大业主");
        fb1.setTypeId("A");
        List<FiltrateBean.Children> childrenList = new ArrayList<>();
        for (int x = 0; x < sexs.length; x++) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(sexs[x]);
            cd.setId(idS[x]);
            childrenList.add(cd);
        }
        fb1.setChildren(childrenList);

        FiltrateBean fb2 = new FiltrateBean();
        fb2.setTypeName("是否优质房源");
        fb2.setTypeId("B");
        List<FiltrateBean.Children> childrenList2 = new ArrayList<>();
        for (int x = 0; x < colors.length; x++) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(colors[x]);
            cd.setId(idS[x]);
            childrenList2.add(cd);
        }
        fb2.setChildren(childrenList2);

        FiltrateBean fb3 = new FiltrateBean();
        fb3.setTypeName("状态");
        fb3.setTypeId("C");
        List<FiltrateBean.Children> childrenList3 = new ArrayList<>();
        for (int x = 0; x < company.length; x++) {
            FiltrateBean.Children cd = new FiltrateBean.Children();
            cd.setValue(company[x]);
            cd.setId(statusId[x]);
            childrenList3.add(cd);
        }
        fb3.setChildren(childrenList3);

        dictList.add(fb1);
        dictList.add(fb2);
        dictList.add(fb3);
    }

    int flag = 1;
    private int areaType;
    RecyclerView recyclerView1;
    RecyclerView recyclerView2;
    RecyclerView recyclerView3;
    RecyclerView recyclerView4;
    RecyclerView recyclerView5;

    AreaListAdapter areaListAdapter1;
    AreaListAdapter areaListAdapter2;
    AreaListAdapter areaListAdapter3;
    AreaListAdapter areaListAdapter4;
    AreaListAdapter areaListAdapter5;

    //	1：市 -区-地点 2：楼盘 3：栋座
    private int parentId = 16;

    private void showAreaData() {
        flag = 1;
        parentId = 16;
        CityDetailFilterPopwindow areaFilterPopwindow = new CityDetailFilterPopwindow(getActivity());
        areaFilterPopwindow.showPop(rlArea);
        recyclerView1 = areaFilterPopwindow.getCurrentView(1);
        recyclerView2 = areaFilterPopwindow.getCurrentView(2);
        recyclerView3 = areaFilterPopwindow.getCurrentView(3);
        recyclerView4 = areaFilterPopwindow.getCurrentView(4);
        recyclerView5 = areaFilterPopwindow.getCurrentView(5);

        areaListAdapter1 = new AreaListAdapter();
        areaListAdapter2 = new AreaListAdapter();
        areaListAdapter3 = new AreaListAdapter();
        areaListAdapter4 = new AreaListAdapter();
        areaListAdapter5 = new AreaListAdapter();

        recyclerView1.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView3.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView4.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView5.setLayoutManager(new LinearLayoutManager(getActivity()));

        recyclerView1.setAdapter(areaListAdapter1);
        recyclerView2.setAdapter(areaListAdapter2);
        recyclerView3.setAdapter(areaListAdapter3);
        recyclerView4.setAdapter(areaListAdapter4);
        recyclerView5.setAdapter(areaListAdapter5);

        areaListAdapter1.setSelect(0);


        List<AreaListBean> list1 = new ArrayList<>();
        list1.add(new AreaListBean(16, "区域", "区域"));
        list1.add(new AreaListBean(2, "地铁", "地铁"));
        areaListAdapter1.setNewData(list1);
        recyclerView1.post(new Runnable() {
            @Override
            public void run() {
                View viewByPosition = recyclerView1.getLayoutManager().findViewByPosition(0);
                viewByPosition.performClick();
            }
        });
        getAreaData(flag, 16);
        areaListAdapter1.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                flag = 1;
                areaType = 1;
                areaListAdapter1.setSelect(position);
                if (position == 0) {//城市
                    cityType = 1;
                    getAreaData(flag, 16);
                } else { //地铁
                    cityType = 2;
//                    areaListAdapter1.setNewData(list1);
                    getSubwayData(flag, 0);
                }
            }
        });

        areaListAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                areaListAdapter2.setSelect(position);
                flag = 1;
                areaType = 2;
                AreaListBean areaListBean = (AreaListBean) adapter.getData().get(position);
                parentId = areaListBean.getId();
                if (cityType == 1) {
                    getAreaData(flag, parentId);
                } else {
                    getSubwayData(flag, parentId);
                }
            }
        });

        areaListAdapter3.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                areaListAdapter3.setSelect(position);
                flag = 2;
                areaType = 3;
                AreaListBean areaListBean = (AreaListBean) adapter.getData().get(position);
                parentId = areaListBean.getId();
                if (cityType == 1) {
                    getAreaData(flag, parentId);
                } else {
                    getSubwayData(flag, parentId);
                }
            }
        });
        areaListAdapter4.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                areaListAdapter4.setSelect(position);
                flag = 2;
                areaType = 4;
                AreaListBean areaListBean = (AreaListBean) adapter.getData().get(position);
                parentId = areaListBean.getId();
                if (cityType == 1) {
                    getAreaData(flag, parentId);
                } else {
                    getSubwayData(flag, parentId);
                }
            }
        });

        TextView tvSure = (TextView) areaFilterPopwindow.getView(R.id.tv_suer);
        areaFilterPopwindow.getView(R.id.tv_default).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                areaFilterPopwindow.getPopWindow().dissmiss();
                housesBean = new HousesBean();
                housesBean.setPageNum(page);
                housesBean.setPageSize(pageSize);
                loadData();
            }
        });
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                page = 1;
                if (cityType == 1) {
                    housesBean = new HousesBean();
                    housesBean.setPageNum(page);
                    housesBean.setPageSize(pageSize);
                    housesBean.setAreaId(areaListAdapter4.getSelectId());
                    housesBean.setBuildingId(areaListAdapter5.getSelectId());
                    housesBean.setFloorId(areaListAdapter4.getSelectId());
                    housesBean.setPlaceId(areaListAdapter3.getSelectId());
                } else {
                    housesBean = new HousesBean();
                    housesBean.setPageNum(page);
                    housesBean.setPageSize(pageSize);
                    housesBean.setSubwayId(areaListAdapter3.getSelectId());
                    housesBean.setSubwayParentId(areaListAdapter2.getSelectId());
                }
                Log.e("路线", new Gson().toJson(housesBean));
                loadData();
                areaFilterPopwindow.getPopWindow().dissmiss();
                //areaId buildingId floorId floorId
            }
        });
    }

    private void getAreaData(int flag, int parentID) {
        mPresenter.getAreaList(flag, parentID);
    }

    public void getSubwayData(int flag, int parentID) {
        mPresenter.getSubwayData(parentID);
    }

    private HousesListBean housesData;

    @Override
    public void getHouseSuccess(HousesListBean housesListBean) {

    }

    private List<AreaListBean> areaListBeans;

    @Override
    public void getAreaListSuccess(List<AreaListBean> listBeans) {
        areaListBeans = listBeans;
        if (areaType == 1) {
            areaListAdapter2.setNewData(areaListBeans);
            if (areaListBeans.size() <= 0) {
//                areaListAdapter2.se
            }
            recyclerView2.post(new Runnable() {
                @Override
                public void run() {
                    recyclerView2.getLayoutManager().findViewByPosition(0).performClick();
                }
            });
        } else if (areaType == 2) {
            areaListAdapter3.setNewData(areaListBeans);
//            recyclerView3.getLayoutManager().findViewByPosition(0).performClick();
        } else if (areaType == 3) {
            areaListAdapter4.setNewData(areaListBeans);
            recyclerView4.post(new Runnable() {
                @Override
                public void run() {
                    recyclerView4.getLayoutManager().findViewByPosition(0).performClick();
                }
            });
        } else if (areaType == 4) {
            areaListAdapter5.setNewData(areaListBeans);
        }
    }

    @Override
    public void getSubwatdataSuccess(List<AreaListBean> listBeans) {
        areaListBeans = listBeans;
        if (areaType == 1) {
            areaListAdapter2.setNewData(areaListBeans);
            if (areaListBeans.size() <= 0) {
//                areaListAdapter2.se
            }
            recyclerView2.getLayoutManager().findViewByPosition(0).performClick();
        } else if (areaType == 2) {
            areaListAdapter3.setNewData(areaListBeans);
            recyclerView3.getLayoutManager().findViewByPosition(0).performClick();
        } else if (areaType == 3) {
            areaListAdapter4.setNewData(areaListBeans);
            recyclerView4.getLayoutManager().findViewByPosition(0).performClick();
        }
    }

    @Override
    public void onError() {

    }

    @Override
    public void getMatchHousingSuccess(HousesListBean housesListBean) {
        smartRefresh.finishLoadMore();
        smartRefresh.finishRefresh();
        housesData = housesListBean;
        if (housesListBean.getList().size() <= 0 || null == housesListBean) {
            housesListAdapter.setEmptyView(R.layout.layout_nodata_search, recycleView);
        }
        if (tag == 1) {
            housesListAdapter.setNewData(housesListBean.getList());
        } else {
            housesListAdapter.addData(housesListBean.getList());
        }
    }

    @Override
    public void collectHousingSuccess(BaseData baseData, int i) {
        housesListAdapter.getData().get(i).setCollection("1");
        housesListAdapter.notifyItemChanged(i);
        AppUtils.showToast("收藏成功");  //更新客源详情页面
        EventBus.getDefault().post("collectionSuccess");
    }

    @Override
    public void removecollectHousingSuccess(BaseData baseData, int i) {
        housesListAdapter.getData().get(i).setCollection(null);
        housesListAdapter.notifyItemChanged(i);
        AppUtils.showToast("取消收藏成功");
        EventBus.getDefault().post("collectionSuccess");
    }

    @Override
    public void getFloorCountSuccess(HousingCountBean housingCountBean) {

    }

    @Override
    public void getBannerSuccess(List<HomeBannerBean> homeBannerBeans) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void housingEditSuccess(String s) {
        if (s.equals("collectChange")) {
            loadData();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unregisterEventBus(this);
    }
}